#include <stdio.h>
#include <QtGui/QWidget>
#include <QtGui/QGraphicsView>
#include <QtGui/QGraphicsItem>
#include <QtGui/QPainter>
#include <QtGui/QStyle>
#include <QtGui/QStyleOptionGraphicsItem>
#include "../colliding-trains/data.h"
#include "station.h"

#define RADIUS 10

CStation::CStation(QGraphicsItem *graphWidget)
	//:m_graph(graphWidget)
{
	setFlag(ItemIsMovable);
    setFlag(ItemSendsGeometryChanges);
    setCacheMode(DeviceCoordinateCache);
    setZValue(-1);
	m_polygon.clear();
	m_polygon << QPointF(0-RADIUS,0-RADIUS)
		      << QPointF(0-RADIUS,RADIUS)
			  << QPointF(RADIUS,RADIUS)
			  << QPointF(RADIUS,0-RADIUS)
			  << QPointF(0-RADIUS,0-RADIUS);
}


CStation::~CStation(void)
{
	printf("Station removed");
}

void CStation::setstation(const QPointF & point, const QString & name)
{
	this->setX(point.x());
	this->setY(point.y());
	this->m_name = name;
}

QRectF CStation::boundingRect() const
{
	//QRectF rect(this->x(), this->y(), this->x() + RADIUS*2, this->y() + RADIUS*2);
	QRectF rect(0-RADIUS,0-RADIUS,RADIUS*2,RADIUS*2);
	return(rect);
}

/*
QPainterPath CStation::shape() const
{
	 QPainterPath path;
     path.addEllipse(0, 0 , RADIUS, RADIUS);
     return path;
}
*/ 

QPolygonF CStation::polygon()
{
	m_polygon << QPointF(0-(RADIUS),0-(RADIUS))
		      << QPointF(0-(RADIUS),RADIUS)
			  << QPointF(RADIUS,RADIUS)
			  << QPointF(RADIUS,0-(RADIUS))
			  << QPointF(0-(RADIUS),0-(RADIUS));
	return(m_polygon);
}

void CStation::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
/*	painter->setPen(Qt::NoPen);
    painter->setBrush(Qt::darkGray);
    painter->drawEllipse(-7, -7, 20, 20);

    QRadialGradient gradient(-3, -3, 10);
    if (option->state & QStyle::State_Sunken) {
        gradient.setCenter(3, 3);
        gradient.setFocalPoint(3, 3);
        gradient.setColorAt(1, QColor(Qt::yellow).light(120));
        gradient.setColorAt(0, QColor(Qt::darkYellow).light(120));
    } else {
        gradient.setColorAt(0, Qt::yellow);
        gradient.setColorAt(1, Qt::darkYellow);
    }
    painter->setBrush(gradient);
    painter->setPen(QPen(Qt::black, 0));
    painter->drawEllipse(-10, -10, 20, 20);
	*/

	QRadialGradient gradient(-3, -3, 10);
	gradient.setColorAt(0, Qt::yellow);
    gradient.setColorAt(1, Qt::darkYellow);
	painter->setBrush(gradient);
	painter->setPen(QPen(Qt::blue, 1, Qt::SolidLine, Qt::RoundCap,Qt::RoundJoin));
	QPoint point(0,0);
	//painter->drawPolygon(polygon());
	painter->drawEllipse(point, RADIUS, RADIUS);
}